﻿using System.Windows.Forms;

namespace Outlook.WorkItems.Extension.Controls
{
    /// <summary>
    /// This Class represent a node in a treeview for a Document Librairy
    /// </summary>
    public class DocumentLibrairyNode : TreeNode
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="text">Node Text</param>
        /// <param name="viewUrl"></param>
        public DocumentLibrairyNode(string text, string viewUrl)
            : base(text)
        {
            this.ImageIndex = 3;
            this.SelectedImageIndex = 3;
            this.Tag = viewUrl;
        }

        /// <summary>
        /// Returns parent node of type Team Server Node
        /// </summary>
        public TeamServerNode TeamServerNode
        {
            get
            {
                TreeNode currentNode = this;
                while (!(currentNode is TeamServerNode) && currentNode != null)
                {
                    currentNode = currentNode.Parent;
                }
                return currentNode as TeamServerNode;
            }
        }

        /// <summary>
        /// Returns parent node of type Team Project Node
        /// </summary>
        public TeamProjectNode TeamProjectNode
        {
            get
            {
                TreeNode currentNode = this;
                while (!(currentNode is TeamProjectNode) && currentNode != null)
                {
                    currentNode = currentNode.Parent;
                }
                return currentNode as TeamProjectNode;
            }
        }
    }
}
